home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume9 / rwhoparse < prev    next >
Encoding:
Text File  |  1989-12-12  |  5.7 KB  |  203 lines

  1. Newsgroups: comp.sources.misc
  2. keywords: 
  3. organization: Colorado State University, Fort Collins, CO  80523
  4. subject: v09i060: rwho parser prints real names
  5. from: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6. Reply-To: robert@longs.LANCE.ColoState.Edu (Robert Thompson)
  7.  
  8. Posting-number: Volume 9, Issue 60
  9. Submitted-by: robert@longs.LANCE.ColoState.Edu (Robert Thompson)
  10. Archive-name: rwhoparse
  11.  
  12. Here is a program that you might find useful, people arround here have.  It
  13. parses the output from rwho and returns some interesting information.
  14.  
  15.     -Robert
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of shell archive."
  24. # Contents:  README Makefile rwhop.n rwhoparse.c
  25. # Wrapped by robert@longs.LANCE.ColoState.Edu on Mon Dec 11 21:16:41 1989
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'README' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'README'\"
  29. else
  30. echo shar: Extracting \"'README'\" \(595 characters\)
  31. sed "s/^X//" >'README' <<'END_OF_FILE'
  32. rwhop is a program I wrote one bored Sunday night for something to do.  I
  33. was prompted to post this code for others to use.  The main reason for the
  34. program is to return the users real name instead of just the login name.
  35. If there are any problems, send me mail and I will try to rectify the bug.
  36. X
  37. This coed is supplied without copyright, do with it what you please.  (Tell
  38. me of any improvements you have.)  I was thinking of making the program
  39. search for a host rather than just a user (maybe someday).  
  40. X
  41. Robert
  42. CSU - Center forComputer Assisted Engineering
  43. X
  44. robert@longs.LANCE.ColoState.Edu
  45. END_OF_FILE
  46. if test 595 -ne `wc -c <'README'`; then
  47.     echo shar: \"'README'\" unpacked with wrong size!
  48. fi
  49. # end of 'README'
  50. fi
  51. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  52.   echo shar: Will not clobber existing file \"'Makefile'\"
  53. else
  54. echo shar: Extracting \"'Makefile'\" \(469 characters\)
  55. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  56. X#################################################################
  57. X#
  58. X# rwhoparse makefile created 12/10/89
  59. X#
  60. X# No copyrights inplied or requested.  This code is supplied as is
  61. X# have fun using it and report any bugs to:
  62. X#
  63. X#      robert@longs.LANCE.ColoState.edu
  64. X#
  65. X#################################################################
  66. OBJS=    rwhoparse.o
  67. SRCS=    rwhoparse.c
  68. X
  69. TARGET= rwhop
  70. CC= gcc -O -ansi
  71. X
  72. all:    
  73. X    $(CC) -o $(TARGET) rwhoparse.c 
  74. X    
  75. clean:
  76. X    rm -f *.o $(TARGET) core
  77. END_OF_FILE
  78. if test 469 -ne `wc -c <'Makefile'`; then
  79.     echo shar: \"'Makefile'\" unpacked with wrong size!
  80. fi
  81. # end of 'Makefile'
  82. fi
  83. if test -f 'rwhop.n' -a "${1}" != "-c" ; then 
  84.   echo shar: Will not clobber existing file \"'rwhop.n'\"
  85. else
  86. echo shar: Extracting \"'rwhop.n'\" \(1083 characters\)
  87. sed "s/^X//" >'rwhop.n' <<'END_OF_FILE'
  88. X.\" SCCSID: @(#)rwhop.n 1.0 12/10/89
  89. X.TH rwhop n
  90. X.SH NAME
  91. rwhop \- rwho(1) output parser
  92. X.SH SYNTAX
  93. X.B rwhop
  94. X[
  95. X.B \-ah
  96. X] [\fIusers\fR]
  97. X.SH DESCRIPTION
  98. The
  99. X.PN rwhop
  100. command takes the output from rwho(1) via a pipe stream connection.
  101. The returned information is the same as that of rwho with the following
  102. exceptions: 1) fully qualified host names are truncated to the first level.
  103. X2) The users' gecos information is retreived via the getpwnam(3) call.
  104. The first field of the gecos information is printed un the heading of 'Real
  105. Name'
  106. X.SH OPTIONS
  107. X.IP \fB\-a\fR 20
  108. Lists all users.  Normally,
  109. X.PN rwhop
  110. omits users who have not typed to the system for an hour or
  111. more.  If the
  112. X.B \-a
  113. flag is specified, these users are also listed.
  114. X.IP \fB\-h\fR 20
  115. Sorts users by host name.  Normally,
  116. X.PN rwhop
  117. prints its output sorted by user name.  If the
  118. X.B \-h
  119. flag is specified, the results are sorted by host name.
  120. X.SH FILES
  121. X/usr/spool/rwho/whod.*    Information about other machines
  122. X.SH SEE ALSO
  123. ruptime(1c), rwhod(8c)
  124. X.SH AUTHOR
  125. Robert D. Thompson - Colorado State University  December 10, 1989
  126. END_OF_FILE
  127. if test 1083 -ne `wc -c <'rwhop.n'`; then
  128.     echo shar: \"'rwhop.n'\" unpacked with wrong size!
  129. fi
  130. # end of 'rwhop.n'
  131. fi
  132. if test -f 'rwhoparse.c' -a "${1}" != "-c" ; then 
  133.   echo shar: Will not clobber existing file \"'rwhoparse.c'\"
  134. else
  135. echo shar: Extracting \"'rwhoparse.c'\" \(1024 characters\)
  136. sed "s/^X//" >'rwhoparse.c' <<'END_OF_FILE'
  137. X#include <stdio.h>
  138. X#include <pwd.h>
  139. X#define RWHO "/usr/ucb/rwho "
  140. X
  141. main(argc,argv)
  142. int    argc;
  143. char    *argv[];
  144. X{
  145. X    FILE    *pipe;
  146. X
  147. X    char    real_name[20], inline[80];
  148. X    char    *user, *host, *time, *gecos, *tty, *strtok();
  149. X
  150. X    register int i;
  151. X
  152. X    struct    passwd    *pw;
  153. X
  154. X    argv++;
  155. X    strcpy(inline,RWHO);
  156. X    strcat(inline,*argv);
  157. X
  158. X    if ((pipe = popen(inline,"r")) == NULL)
  159. X        {
  160. X        fprintf (stderr,"Broken pipe\n");
  161. X        exit(-1);
  162. X        }
  163. X    
  164. printf ("User                 Real Name        Host   TTY    When         Idle\n");
  165. X    for (i=0;i<80;i++) printf ("-");
  166. X    printf ("\n");
  167. X
  168. X    while (fgets(inline,80,pipe) != NULL)
  169. X        {
  170. X        user = strtok(inline," ");
  171. X        host = strtok(NULL,":");
  172. X        tty = strtok(NULL," ");
  173. X        time = strtok(NULL,"\n");
  174. X
  175. X        if ((pw = getpwnam(user)) != NULL)
  176. X            {
  177. X            gecos = strtok(pw->pw_gecos,",");
  178. X            
  179. X            strncpy(real_name,gecos,20);
  180. X            real_name[20] = NULL;
  181. X            
  182. X            while(time[0] == ' ') time++;
  183. X            while(host[0] == ' ') host++;
  184. X            
  185. X            printf ("%8s  %20s  %10s  %6s  %s\n",
  186. X                user,
  187. X                real_name,
  188. X                strtok(host,"."),
  189. X                tty,
  190. X                time);
  191. X            }
  192. X        }
  193. X}
  194. END_OF_FILE
  195. if test 1024 -ne `wc -c <'rwhoparse.c'`; then
  196.     echo shar: \"'rwhoparse.c'\" unpacked with wrong size!
  197. fi
  198. # end of 'rwhoparse.c'
  199. fi
  200. echo shar: End of shell archive.
  201. exit 0
  202.  
  203.